// PC端
var index = 0;
var timer = null;

function autoPlay() {
    index++;
    if (index > $('.bannerList>div').length - 1) {
        index = 0;
    }
    $('.bannerList>div').eq(index).fadeIn(800).siblings().fadeOut(800);
    $('.index_banner .bar .barList>div').eq(index).addClass('active').siblings().removeClass('active');
}

timer = setInterval(function () {
    autoPlay();
}, 3000)

$('.index_banner .bar .barList>div').on('click', function () {
    $(this).addClass('active').siblings().removeClass('active');
    $('.index_banner .bannerList>div').eq($(this).index()).stop().fadeIn(800).siblings().fadeOut(800);
    clearInterval(timer);
    timer = setInterval(autoPlay, 3000);
    return index = $(this).index();
})

$(window).on('resize', function () {
    var pcHeight = $(".index_banner .pc .bannerList .bannerImg").height();
    pcHeight = Math.floor(pcHeight)
    $('.index_banner .pc').css('height', pcHeight)
})

$('.index_banner .pc .bannerList').on('mouseover', function () {
    clearInterval(timer);
    clearInterval(mobile_timer);
})

$('.index_banner .pc .bannerList').on('mouseout', function () {
    timer = setInterval(autoPlay, 3000);
    mobile_timer = setInterval(moblie_autoPlay, 3000);
})

// 移动端下
var mobile_index = 0
var mobile_timer = null

function moblie_autoPlay() {
    mobile_index++;
    if (mobile_index > $('.mobile_bannerList>div').length - 1) {
        mobile_index = 0;
    }
    $('.mobile_bannerList>div').eq(mobile_index).fadeIn(500).siblings().fadeOut(500);
    $('.index_banner .mobile_bar ul li').eq(mobile_index).addClass('liActive').siblings().removeClass('liActive');
}

mobile_timer = setInterval(function () {
    moblie_autoPlay()
}, 3000)

$('.index_banner .mobile_bar ul li').on('click', function () {
    $(this).addClass('liActive').siblings().removeClass('liActive');
    $('.index_banner .mobile_bannerList>div').eq($(this).index()).fadeIn(800).siblings().fadeOut(800);
    clearInterval(mobile_timer);
    mobile_timer = setInterval(autoPlay, 3000);
    return mobile_index = $(this).index();
})



$('.index_banner .mobile_bannerList').on('mouseover', function () {
    clearInterval(mobile_timer);
    clearInterval(timer);
})

$('.index_banner .mobile_bannerList').on('mouseout', function () {
    mobile_timer = setInterval(moblie_autoPlay, 3000);
    timer = setInterval(autoPlay, 3000);
})

// 获取mobile的高度
$(window).on('resize', function () {
    var mobileHeight = $(".index_banner .mobile_bannerList .bannerImg").height();
    mobileHeight = Math.floor(mobileHeight)
    console.log(mobileHeight);
    $('.index_banner .mobile').css('height', mobileHeight)
})